package com.gx.smart.construction.ui.common.page.viewmodel;

import android.app.Application;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.ToastUtils;
import com.casic.gx.grpc.common.ComQuery;
import com.casic.gx.grpc.common.ComResp;
import com.gx.smart.base.BaseViewModel;
import com.gx.smart.base.livedata.SingleLiveEvent;
import com.gx.smart.construction.R;
import com.gx.smart.lib.http.api.ConstructionAppOrganizationalStructureProviderService;
import com.gx.smart.lib.http.api.asynctask.CallBack;
import com.gx.wisestone.constructionappgrpclib.grpc.organizationalstructure.ConstructionAppOrganizationalStructureDto;
import com.gx.wisestone.constructionappgrpclib.grpc.organizationalstructure.ConstructionAppOrganizationalStructureQueryResponse;

import java.util.List;

/**
 * @author: xiaosy
 * 时间: 2021/11/19
 * @Description: 查询房屋列表模块
 * @Version: 1.0
 **/
public class SearchRoomViewModel extends BaseViewModel {
    public SingleLiveEvent<List<ConstructionAppOrganizationalStructureDto>> roomList = new SingleLiveEvent<>();
    public SearchRoomViewModel(@NonNull Application application) {
        super(application);
    }
    public static final int MAX_ROOM_NUM = 10000;
    public void roomList(String parentId) {
        ComQuery comQuery = ComQuery
                .newBuilder()
                .setPageSize(MAX_ROOM_NUM)
                .setPage(1)
                .build();
        ConstructionAppOrganizationalStructureProviderService.getInstance().queryOrganizationalStructure(comQuery, parentId, 4, new CallBack<ConstructionAppOrganizationalStructureQueryResponse>() {

            @Override
            public void callBack(ConstructionAppOrganizationalStructureQueryResponse result) {
                if (result == null) {
                    error.setValue(true);
                    ToastUtils.showLong("服务器超时");
                    return;
                }

                ComResp comResp = result.getComResp();
                if (comResp.getCode() == 100) {
                    roomList.setValue(result.getContentList());
                } else {
                    error.setValue(true);
                    handleServiceException(comResp);
                }
            }
        });
    }

}
